import DialogEditPageConfig from '../components/DialogEditPageConfig.vue'
import {
  editPageConfig,
  deletePage
} from '@/views/wxaBuildModule/api/page'
export default {
  components: {
    DialogEditPageConfig
  },
  methods: {
    /**
     * 按钮组
     */
    // 编辑配置
    editPage() {
      this.$bus.emit('wxaBuildModuleChangePageMode', 'module')
      // 初始化函数
      this.$bus.emit('wxaBuildModuleChangePageInit')
      const { modules } = this.activePageForm
      const keys = []
      modules.forEach((item) => {
        keys.push(item.type)
      })
      this.$store.dispatch('setSelectedKeys', keys)
    },

    // 基础配置
    editConfig(id) {
      this.$refs.editPageConfig.open({ mode: 'edit', id }).then(res => {
        this.$bus.emit('wxaBuildModuleRefreshAsidePageList', { refreshActive: false })
      })
    },

    // 使用页面
    usePage(row) {
      console.log(row)
      const params = {
        params: { classifyCode: this.classifyCode },
        data: {
          id: row.id,
          primaryPage: true,
          subType: row.subType,
          type: row.type
        }
      }
      this.loading = true
      editPageConfig(params).then(res => {
        this.$bus.emit('wxaBuildModuleRefreshAsidePageList', { refreshActive: false })
        this.$notify({
          title: '成功',
          message: '设置成功',
          type: 'success',
          duration: 2000,
          offset: 40
        })
      }).catch(err => {
      }).finally(() => {
        this.loading = false
      })
    },

    // 删除页面
    delPage(row) {
      const params = {
        classifyCode: this.classifyCode,
        pageId: row.id
      }
      this.loading = true
      deletePage(params).then(res => {
        this.$bus.emit('wxaBuildModuleRefreshAsidePageList')
        this.$notify({
          title: '成功',
          message: '删除成功',
          type: 'success',
          duration: 2000,
          offset: 40
        })
      }).catch(err => {
      }).finally(() => {
        this.loading = false
      })
    }
  }

  // 编辑模块

}
